<script setup>
import { onMounted, ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import { loginByToken } from "../../services/login";
import { elNotificationStore } from "../../store/LoginSuccessStore";
import { isLoginStore } from "../../store/IsLoginStore";
import { storeToRefs } from "pinia";
const isLogin = isLoginStore();
let { isLoginFlag, isLoginBox } = storeToRefs(isLogin);
const elNotStore = elNotificationStore();
const loading = ref(true);
onMounted(() => {
  const router = useRouter();
  const token = useRoute().query.token;
  localStorage.setItem("Authorization", token);
  const type = 1;
  loginByToken(type)
    .then((res) => {
      let userData = {
        username: res.data.username, //账号
        fullName: res.data.fullName, // 姓名
        headPic: res.data.headPic, // 头像
        endTime: res.data.endTime, //最新登录时间
        roleName: res.data.roleName, //角色
        id: res.data.id,
      };
      localStorage.setItem("userData", JSON.stringify(userData));
      isLoginFlag.value = true;
      isLoginBox.value = false;
      router.push("/main");
      elNotStore.setIsShow(1);
    })
    .catch((error) => {
      router.push("/main");
    });
});
</script>
<template>
  <div v-loading="loading" style="height: 100%; width: 100%"></div>
</template>

<style lang="less" scoped></style>
